#include "audiotask.h"
#include "generator.h"
AudioTask::AudioTask(AVStream *pAVStream,AVCodec *pAVCodec)
{
    m_generator = new Generator(pAVStream,pAVCodec);

    m_generator->start();

    format      = new QAudioFormat;

    format->setSampleRate(pAVStream->codec->sample_rate);
    format->setChannelCount(pAVStream->codec->channels);
    format->setSampleSize(16);
    //pAVStream->codec->bits_per_coded_sample 这个设置有疑问 应该是16
    format->setCodec("audio/pcm");
    format->setByteOrder(QAudioFormat::LittleEndian);
    format->setSampleType(QAudioFormat::UnSignedInt);

    audio = new QAudioOutput( *format, 0);
    //audio->start(&inputFile);
    audio->start(m_generator);
}
AudioTask::~AudioTask()
{
    audio->stop();

    m_generator->stop();

    delete m_generator;

    delete format;

}

void AudioTask::appendAudioPacket(const AVPacket &aVpkt1)
{
    if(m_generator)
        m_generator->appendAudioPacket(aVpkt1);
}

double AudioTask::get_audio_clock()
{
    return m_generator->get_audio_clock();
}

